package work.chenbo.spring_boot_shiro.modules.sys_user.constant;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ChenBo
 * @enumName ErrorCodeEnum
 * @date 2019/11/8
 */
public enum ErrorCodeEnum {
    ADD_FAIL(1001,"添加失败"),
    UPDATE_FAIL(1002,"修改失败"),
    SUCCESS(200,"操作成功");
    private Integer code;
    private String msg;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    ErrorCodeEnum(int code, String msg) {
        this.code=code;
        this.msg = msg;
    }

    public static String getMsg(int code) {
        Map<Integer, String> enumMap = Arrays.stream(ErrorCodeEnum.values())
                .collect(Collectors.toMap(ErrorCodeEnum::getCode, ErrorCodeEnum::getMsg));
        return enumMap.get(code);
    }
}
